﻿using System;
using System.Windows.Forms;
using HHL_BusAcc.BussinessObject;
using HHL_TranferAcc;
using HHL_Util;

//aa
namespace HHL_Acc
{
    public partial class PhieuNhapKhoFRM : Form
    {
        private int count = 0;

        public PhieuNhapKhoFRM()
        {
            InitializeComponent();
            InitDanhSachPhieuNhap();
            InitThongTinChiTiet();
            // this.MdiParent = MDI_FRM;
        }

        #region "Thong Tin Chi Tiet"

        private void InitThongTinChiTiet()
        {
            //GenLogins currLogin = SessionUser.GenLogin
            txtTabTTCTNguoiNhan.Text = SessionUser.GenLogin.Name;
        }
        private void btnThemThongTinVe_Click(object sender, EventArgs e)
        {
            if (gvTabTTCTThongTinVe.Rows.Count > 0)
            {
                count++;
            }
            String donGia = CommonUtil.ConvertCurrencyToString((long)txtTabTTCTDonGiaVe.Value);
            String soLuong = CommonUtil.ConvertCurrencyToString((long)txtTabTTCTSoLoc.Value);
            //   String donGia = common
            gvTabTTCTThongTinVe.Rows.Add(new Object[]
                                         {
                                             count, donGia, soLuong, txtTabTTCTSoSerailBD.Text,
                                             txtTabTTCTSoSerialKT.Text
                                         });
        }


        private void gviewThongTinVe_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
        {
            DialogResult result = MessageBox.Show("Bạn có muốn xóa những thông tin này không?", "Thông báo",
                                                  MessageBoxButtons.YesNo);
            //gviewThongTinVe.SelectedRows
            if (result == System.Windows.Forms.DialogResult.Yes)
            {
                count = gvTabTTCTThongTinVe.Rows.Count;
                for (int i = 0; i < count - 1; i++)
                {
                    gvTabTTCTThongTinVe.Rows[i].Cells["Index"].Value = (i + 1);
                }
            }
        }
        #endregion

        #region "Danh Sach Phieu Nhap"
        public void InitDanhSachPhieuNhap()
        {
            gvTabDSPNNhapKho.AutoGenerateColumns = false;
            SmiImportsBus smiImportsBus = new SmiImportsBus();
            gvTabDSPNNhapKho.DataSource = smiImportsBus.GetListSmiImportL();

            dtTabDSPNNgayNhapFrom.Value = new DateTime(CommonConstant.TICK_DATE_MIN);

            int currentYear = DateTime.Now.Year;
            int i = currentYear - 5;
            while (i <= (currentYear + 5))
            {
                cboxTabDSPNYear.Items.Add(i);
                i++;
            }
            cboxTabDSPNYear.SelectedIndex = 5;


        }
        private void btnTabDSPNSearch_Click(object sender, EventArgs e)
        {
            SmiImportsBus smiImportsBus = new SmiImportsBus();
            int? imNumber = null;
            int? year = null;
            if (txtTabDSPNPhieuNhap.Text.TrimEnd() != String.Empty)
            {
                imNumber = int.Parse(txtTabDSPNPhieuNhap.Text);
            }
            if (cboxTabDSPNYear.SelectedText.TrimEnd() != String.Empty)
            {
                year = int.Parse(cboxTabDSPNYear.SelectedText);
            }
            
            gvTabDSPNNhapKho.DataSource = smiImportsBus.GetListSmiImport(imNumber, year,
                dtTabDSPNNgayNhapFrom.Value, dtTabDSPNNgayNhapTo.Value);
            
        }
       

        private void button5_Click(object sender, EventArgs e)
        {
            SmiImports smiImports = new SmiImports();
            Random rand = new Random();

            smiImports.ImpId = rand.Next(10000) +"";
            
            //smiImports.Login = 
        }

        #endregion

        private void txtTabTTCTSoLoc_ValueChanged(object sender, EventArgs e)
        {

        }


        /*
        private void gvTabDSPNNhapKho_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewCellStyle styleBlank = new DataGridViewCellStyle();
            styleBlank.BackColor = Color.White;
            for (int i = 0; i < gvTabDSPNNhapKho.Rows.Count; i++)
            {
                gvTabDSPNNhapKho.Rows[i].DefaultCellStyle = styleBlank;
            }

            gvTabDSPNNhapKho.RowsDefaultCellStyle = new DataGridViewCellStyle();
            DataGridViewCellStyle styleOver = new DataGridViewCellStyle();
            styleOver.BackColor = Color.LightBlue;
            if (e.RowIndex != -1 )
            {
                gvTabDSPNNhapKho.Rows[e.RowIndex].DefaultCellStyle = styleOver;
            }
        }*/
    }
}